devfandomcom-20200223-history
UTCClock
| Code = code.js | Languages = auto | Type = site }} UTCClock adds a clock displaying the current time in the UTC timezone to the header on Oasis. This is helpful in figuring out how long ago comments were posted on talk pages and forums since the user's signature shows the time in UTC when it was posted. Installation Configuration Custom Clock Face Text // Display 12 hour time followed by day, month (English, full name) // and year with "(UTC)" at the end window.DisplayClockJS = '%2I:%2M:%2S %p %2d %{January;February;March;April;May;June;July;August;September;October;November;December}m %Y (UTC)'; This last syntax is the most powerful, but that also makes it the most complicated. See the Instructions here. It's also possible to position the clock inside the bottom toolbar and configure various other features if you want to do that: // Display 12 hour time followed by day, month (English, full name) // and year with "(UTC)" at the end window.DisplayClockJS = { format: '%2I:%2M:%2S %p %2d %{January;Febuary;March;April;May;June;July;August;September;October;November;December}m %Y (UTC)', location: 'toolbar', hoverText: 'This is what the user sees when they hover their mouse over the link', interval: 500, /* How often the timer updates in milliseconds (1000=1 second) */ monofonts: 'Consolas, monospace', /* The font the clock uses by default */ offset: 480 /* Time offset from UTC in minutes - 480 changes the clock from UTC to CST (China Standard Time) */ }; importArticle({type:'script', article:'w:c:dev:DisplayClock/code.js'}); Code interface You can modify the value of DisplayClockJS.format while the clock is running which will instantly change the text it displays for you. There is also a kill function that will stop the clock and remove it from the UI for you: DisplayClockJS.kill(). can access these via your JavaScript console if you need them for some reason as the live editing of the format string can be useful for experimenting with the options Changing the Appearance The clock element has the id DisplayClockJS, so you can apply CSS rules to change the appearance: /* When displaying in the header */ a#DisplayClockJS { color: red !important } /* When displaying in the bottom toolbar / other skins */ li#DisplayClockJS > a { color: red !important } /* Use a Monospace font */ #DisplayClockJS { font-family: 'Lucida Console', monospace } Users can hide the clock by inserting the code below into their personal CSS: #DisplayClockJS { display: none; } Customising the Clock The clock syntax is based on the C/C++ strftime function but slightly different. Basically, window.DisplayClockJS takes an arbitrary block of text that will appear unchanged on the clock except for the magic % symbols. Each %symbol has the following form: Type 1: % Example: %d = Current day of the month, no minimum length (e.g. 2) %2d = Current day of the month, force it to always have at least 2 characters (e.g. 02) Type 2: % {} Example: %{Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday}w = Displays English day of the week Type 3: %% = Produces a single % symbol The last item in a list will be used for everything greater than the length of the list. If there are only 6 entries in a day of the week list, then the last one (6th) will be used for both of the last 2 days of the week. Unlike strftime, there are no default minimum lengths. If you don't supply your own width number, then it will always be only as wide as necessary. If you want the day of the month number to always be 2 characters wide, then you must ask for that specifically using %2d instead of just %d.